<!DOCTYPE html>
<!-- This test cannot be upstreamed to WPT because it tests we don't crash while canceling
  the imported style sheet load. -->
<meta charset="utf-8">
<title>Canceling the imported style sheet load should not cause a crash</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>
var resolve_done;
var done_was_called = new Promise(resolve => resolve_done = resolve);
// Called by the iframe when done.
function done(result) { resolve_done(result); }

// This test creates a controlled iframe that does import a style sheet file
// via the Service Worker and cancels by removing the style element.
promise_test(t => {
    var worker = 'resources/css-import-crash-worker.js';
    var scope = 'resources/css-import-crash-iframe.html';
    return service_worker_unregister_and_register(t, worker, scope)
      .then(reg => {
           add_completion_callback(() => reg.unregister());
           return wait_for_state(t, reg.installing, 'activated');
         })
      .then(() => with_iframe(scope))
      .then(() => done_was_called)
      .then(result => assert_equals(result, 'Pass'));
  }, 'Canceling the imported style sheet load should not cause a crash.');
</script>
